package cn.com.aiton.common.utils;

import cn.com.aiton.common.model.ServiceResult;
import cn.com.aiton.common.model.extend.AitonExtendGbtDirecDomain;
import cn.com.aiton.common.model.gbt209992007.GbtChannelDomain;
import cn.com.aiton.common.model.gbt209992007.GbtPhaseDomain;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class JsonToSeniorPhaseListUtil {

    private static final Logger LOG =
            LoggerFactory.getLogger(JsonToSeniorPhaseListUtil.class);
    private static final ObjectMapper objectMapper = new ObjectMapper();
    public static ServiceResult<List<GbtChannelDomain>> channelList(String json){
        ServiceResult<List<GbtChannelDomain>> message = new ServiceResult();
        try{
            List<GbtChannelDomain> listll = objectMapper.readValue(json, new TypeReference<List<GbtChannelDomain>>(){});
            message.setSuccess(true);
            message.setObject(listll);
            return message;
        }catch (Exception e){
            LOG.error(e.getMessage(),e);
            message.setSuccess(false);
            return message;
        }
    }

    public static ServiceResult<List<GbtPhaseDomain>> phaseList(String json){
        ServiceResult<List<GbtPhaseDomain>> message = new ServiceResult();
        try{
            List<GbtPhaseDomain> listll = objectMapper.readValue(json, new TypeReference<List<GbtPhaseDomain>>(){});
            message.setSuccess(true);
            message.setObject(listll);
            return message;
        }catch (Exception e) {
            LOG.error(e.getMessage(),e);
            message.setSuccess(false);
            return message;
        }
    }

    public static ServiceResult<List<AitonExtendGbtDirecDomain>> directList(String json){
        ServiceResult<List<AitonExtendGbtDirecDomain>> message = new ServiceResult();
        try{
            List<AitonExtendGbtDirecDomain> listll = objectMapper.readValue(json, new TypeReference<List<AitonExtendGbtDirecDomain>>(){});
            message.setSuccess(true);
            message.setObject(listll);
            return message;
        }catch (Exception e) {
            LOG.error(e.getMessage(),e);
            message.setSuccess(false);
            return message;
        }
    }
}
